package com.sh.activitystudy;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class ActionUriActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_action_uri);
        findViewById(R.id.btu_dial).setOnClickListener(this);
        findViewById(R.id.btu_sms).setOnClickListener(this);
        findViewById(R.id.btu_my).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        String phone = "33221122";
        if ( v.getId() == R.id.btu_dial){
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_DIAL);
            Uri uri = Uri.parse("tel:" + phone);
            intent.setData(uri);
            startActivity(intent);
        }else if (v.getId() == R.id.btu_sms){
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SENDTO);
            Uri uri = Uri.parse("smsto:" + phone);
            intent.setData(uri);
            startActivity(intent);
        } else if (v.getId() == R.id.btu_my) {
            Intent intent = new Intent();
            intent.setAction("android.intent.action.NING");
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            startActivity(intent);
        }

    }
}